/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.akro.db;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.akro.Main;

/**
 *
 * @author Jose Carlos Palma
 * @version v1.0
 */
public class ReaderInbox extends Thread {

    private boolean running = false;

    private OracleDB db;

    private String inbox;

    public ReaderInbox(String db) {
        this.inbox = db;
        this.db = new OracleDB(db);
    }

    @Override
    public synchronized void start() {
        super.start();
        running = true;
    }

    @Override
    public void run() {
        System.out.println("INFO>>> InBox[" + inbox + "] esta iniciado!");
        this.db.connect();
        while (Main.running && running) {
            db.readInbox();
            sleeping(db.getTime());
            return;
        }
        this.db.close();
    }

    private void sleeping(long mili) {
        try {
            sleep(mili);
        } catch (InterruptedException ex) {
        }
    }

    public void stopReader() {
        running = false;
    }
}
